﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefReworkData" :model="stateReworkData.vmModel" label-width="100px">
    <div style="margin-bottom:10px;">{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_WoId_FormItem" prop="LinkedVM.WoId" :label="$t('message.autotrans._Model_ReworkData_WoId')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.WoId" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_WoCode_FormItem" prop="LinkedVM.WoCode" :label="$t('message.autotrans._Model_ReworkData_WoCode')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.WoCode" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ProductId_FormItem" prop="LinkedVM.ProductId" :label="$t('message.autotrans._Model_ReworkData_ProductId')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.ProductId" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ProductName_FormItem" prop="LinkedVM.ProductName" :label="$t('message.autotrans._Model_ReworkData_ProductName')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.ProductName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Sn_FormItem" prop="LinkedVM.Sn" :label="$t('message.autotrans._Model_ReworkData_Sn')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.Sn" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ReTypeId_FormItem" prop="LinkedVM.ReTypeId" :label="$t('message.autotrans._Model_ReworkData_ReType')">
          <el-select v-model="stateReworkData.vmModel.LinkedVM.ReTypeId" clearable>
             <el-option v-for="item in stateReworkData.AllReTypes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ReTypeDesc_FormItem" prop="LinkedVM.ReTypeDesc" :label="$t('message.autotrans._Model_ReworkData_ReTypeDesc')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.ReTypeDesc" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ReasonName_FormItem" prop="LinkedVM.ReasonName" :label="$t('message.autotrans._Model_ReworkData_ReasonName')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ReworkData_ReasonName')}), trigger: 'blur' }]" >
          <el-input v-model="stateReworkData.vmModel.LinkedVM.ReasonName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ReasonCode_FormItem" prop="LinkedVM.ReasonCode" :label="$t('message.autotrans._Model_ReworkData_ReasonCode')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ReworkData_ReasonCode')}), trigger: 'blur' }]" >
          <el-input v-model="stateReworkData.vmModel.LinkedVM.ReasonCode" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Remark_FormItem" prop="LinkedVM.Remark" :label="$t('message.autotrans._Model_ReworkData_Remark')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.Remark" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Operation_FormItem" prop="LinkedVM.Operation" :label="$t('message.autotrans._Model_ReworkData_Operation')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.Operation" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Data_FormItem" prop="LinkedVM.Data" :label="$t('message.autotrans._Model_ReworkData_Data')">
          <el-input v-model="stateReworkData.vmModel.LinkedVM.Data" clearable></el-input>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitReworkData"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onCloseReworkData"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageReworkManagementReworkDataBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { reworkdataApi } from '/@/api/reworkmanagement/reworkdata';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefReworkData = ref();
const stateReworkData = reactive({
    vmModel: {
	  LinkedVM:{
        WoCode: '',
        ProductName: '',
        Sn: '',
        ReTypeId: null,
        ReTypeDesc: '',
        ReasonName: '',
        ReasonCode: '',
        Remark: '',
        Operation: '',
        Data: '',
      },
      Ids:[],
      
	},
    
    AllReTypes: [] as any[],
});

// 取消
const onCloseReworkData = () => {
    closeDialog();
};

// 提交
const onSubmitReworkData = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefReworkData.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            reworkdataApi().batchedit(stateReworkData.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};


// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/ReworkManagement/ReworkData/GetReworkTypes',[],false).then(x=>{stateReworkData.AllReTypes = x});
    if (ci.attrs["wtmdata"]) {
		stateReworkData.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateReworkData.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

